package org.flyer.toolFrame;

import com.alibaba.fastjson.JSON;
import org.flyer.toolFrame.util.FileUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

import java.io.DataInputStream;
import java.io.File;
import java.io.InputStream;
import java.util.Map;

/**
 * 配置类
 */
@Component()
public class Config {
    //加载配置数据
    @Value("classpath:/configJson.json")
    private Resource configJson;

    public Object getObjectByKey(String keyName){
        try {
            String jsonData = FileUtil.jsonRead(configJson.getInputStream());
            Map<String,Object> parse = (Map<String,Object>) JSON.parse(jsonData);
            return parse.get(keyName);
        } catch (Exception e) {
            System.out.println(e);
            return null;
        }
    }
}
